package com.wangshang.general.commodity.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.general.commodity.po.Commodities;

/**
 * A data access object (DAO) providing persistence and search support for
 * Commodities entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wangshang.general.commodity.po.Commodities
 * @author MyEclipse Persistence Tools
 */

public class CommoditiesDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(CommoditiesDAO.class);
	// property constants
	public static final String COMMODITIES_NAME = "commoditiesName";
	public static final String COMMODITY_KIND_ID = "commodityKindId";
	public static final String COMMODITY_KIND_NAME = "commodityKindName";
	public static final String COMMODITIES_SUB_ATTRIB = "commoditiesSubAttrib";
	public static final String NUM_OF_SELL = "numOfSell";
	public static final String ATTRIB0 = "attrib0";
	public static final String ATTRIB1 = "attrib1";
	public static final String ATTRIB2 = "attrib2";
	public static final String ATTRIB3 = "attrib3";
	public static final String ATTRIB4 = "attrib4";
	public static final String ATTRIB5 = "attrib5";
	public static final String ATTRIB6 = "attrib6";
	public static final String ATTRIB7 = "attrib7";
	public static final String ATTRIB8 = "attrib8";
	public static final String ATTRIB9 = "attrib9";
	public static final String ATTRIB10 = "attrib10";
	public static final String ATTRIB11 = "attrib11";
	public static final String ATTRIB12 = "attrib12";
	public static final String ATTRIB13 = "attrib13";
	public static final String ATTRIB14 = "attrib14";
	public static final String ATTRIB15 = "attrib15";
	public static final String PRODUCER = "producer";

	protected void initDao() {
		// do nothing
	}

	public void save(Commodities transientInstance) {
		log.debug("saving Commodities instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Commodities persistentInstance) {
		log.debug("deleting Commodities instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Commodities findById(java.lang.String id) {
		log.debug("getting Commodities instance with id: " + id);
		try {
			Commodities instance = (Commodities) getHibernateTemplate().get(
					"com.wangshang.general.commodity.Commodities", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Commodities instance) {
		log.debug("finding Commodities instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Commodities instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Commodities as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCommoditiesName(Object commoditiesName) {
		return findByProperty(COMMODITIES_NAME, commoditiesName);
	}

	public List findByCommodityKindId(Object commodityKindId) {
		return findByProperty(COMMODITY_KIND_ID, commodityKindId);
	}

	public List findByCommodityKindName(Object commodityKindName) {
		return findByProperty(COMMODITY_KIND_NAME, commodityKindName);
	}

	public List findByCommoditiesSubAttrib(Object commoditiesSubAttrib) {
		return findByProperty(COMMODITIES_SUB_ATTRIB, commoditiesSubAttrib);
	}

	public List findByNumOfSell(Object numOfSell) {
		return findByProperty(NUM_OF_SELL, numOfSell);
	}

	public List findByAttrib0(Object attrib0) {
		return findByProperty(ATTRIB0, attrib0);
	}

	public List findByAttrib1(Object attrib1) {
		return findByProperty(ATTRIB1, attrib1);
	}

	public List findByAttrib2(Object attrib2) {
		return findByProperty(ATTRIB2, attrib2);
	}

	public List findByAttrib3(Object attrib3) {
		return findByProperty(ATTRIB3, attrib3);
	}

	public List findByAttrib4(Object attrib4) {
		return findByProperty(ATTRIB4, attrib4);
	}

	public List findByAttrib5(Object attrib5) {
		return findByProperty(ATTRIB5, attrib5);
	}

	public List findByAttrib6(Object attrib6) {
		return findByProperty(ATTRIB6, attrib6);
	}

	public List findByAttrib7(Object attrib7) {
		return findByProperty(ATTRIB7, attrib7);
	}

	public List findByAttrib8(Object attrib8) {
		return findByProperty(ATTRIB8, attrib8);
	}

	public List findByAttrib9(Object attrib9) {
		return findByProperty(ATTRIB9, attrib9);
	}

	public List findByAttrib10(Object attrib10) {
		return findByProperty(ATTRIB10, attrib10);
	}

	public List findByAttrib11(Object attrib11) {
		return findByProperty(ATTRIB11, attrib11);
	}

	public List findByAttrib12(Object attrib12) {
		return findByProperty(ATTRIB12, attrib12);
	}

	public List findByAttrib13(Object attrib13) {
		return findByProperty(ATTRIB13, attrib13);
	}

	public List findByAttrib14(Object attrib14) {
		return findByProperty(ATTRIB14, attrib14);
	}

	public List findByAttrib15(Object attrib15) {
		return findByProperty(ATTRIB15, attrib15);
	}

	public List findByProducer(Object producer) {
		return findByProperty(PRODUCER, producer);
	}

	public List findAll() {
		log.debug("finding all Commodities instances");
		try {
			String queryString = "from Commodities";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Commodities merge(Commodities detachedInstance) {
		log.debug("merging Commodities instance");
		try {
			Commodities result = (Commodities) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Commodities instance) {
		log.debug("attaching dirty Commodities instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Commodities instance) {
		log.debug("attaching clean Commodities instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CommoditiesDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (CommoditiesDAO) ctx.getBean("CommoditiesDAO");
	}
}